// run test to see if resizing images is slower than the full res load and playback
int actSeqID=-1;
boolean updateSeq=false;
ArrayList <F_Seq> SeqList;
//ArrayList SeqList;

class F_Seq {
  float[] seedFO = new float[9];
  int FNum; //facet number
  String facetType;
  boolean isActive=false;
  boolean pingPong=false;
  int bgColor = color (0);
  float rotFO;
  String iStr, extStr;
  String pathPre="/mnt/sdcard/";
  int frameCnt;
  int defaultRate=20;  //close to upper limit of playback speed.
  int targetRate;
  int actualRate;
  int frameSkip;
  int remainder;
  boolean skipped;
  int curr;
  PImage img;
  int skipCnt;   //for monitor output
  int loops;
  int frameMult=1;

  F_Seq(int p_FNum, String p_FName, int p_frameCnt) {
    FNum = p_FNum;
    frameCnt = p_frameCnt;

    if (frameCnt>0) {
      facetType="seq";
    }
    if (androidMode) {
      iStr=pathPre+"sakura/f"+p_FName+"/"+p_FName.toLowerCase()+".";
      extStr=".bmp";
    } else {
      iStr=pathPre+"chymera/f"+p_FName+"/"+p_FName.toLowerCase()+".";
      extStr=".png";
    }
  }

  void setupFO(boolean update, float[] uSeed) {
    isActive=true;
    facetAct=true;
    seqAct=true;
    actSeqID=int(facets[FNum][1]);
    knownFacet=FNum;
    if (!update) {
      curr=0;
      seedFO=uSeed;
      skipCnt=0;
      frameSkip=0;
      remainder=0;
      rotFO=0;
      loops=0;
      pingPong=boolean(int(seedFO[6]));
      println("s:ping pong= "+pingPong);
      println("s:speed mult= "+seedFO[2]);
      frameMult=1;
    }
    targetRate=round(seedFO[2]*defaultRate);
    println("F:speed mult: "+seedFO[2]);
    println("F:targetRate: "+targetRate);
    rotFO=seedFO[8];
  }

  void updateFO(float[] uSeed) {
    frameRate(targetRate);
    targetRate=round(seedFO[2]*defaultRate);
    rotFO=seedFO[8];
  }

  PImage drawFO() {
    actualRate=round(frameRate);
    img = loadImage(iStr+nf(curr, 5)+extStr);
    skipped=false;
    if (targetRate-actualRate>=5) {
      frameSkip+=targetRate%actualRate;
      statMsg="T: "+targetRate+" A: "+actualRate+" S: "+frameSkip;
      skipped=boolean(round(frameSkip%targetRate));
      skipCnt+=int(skipped)*frameMult;
      curr+=int(skipped)*frameMult;
    } else {
      curr+=frameMult;
    }
    if (pingPong&&(curr==0||curr>frameCnt)) {
      frameMult=-1*frameMult;
      loops++;
      curr+=frameMult;
    } else {
      if (curr > frameCnt) {
        curr = 0;
        loops++;
      }
    }
    return img;
  }
}
